################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis Tax and Benefit System
#Figure 2
#
#Verena Fetscher
#July 2022
####################



####################
# Load data
####################

load("Benefits.Rda")


##########################
#Descriptives on benefit concentration indicator
##########################

#Benefit concentration indicator mean
df %>%
  group_by(cntry) %>%
  filter(time=="Mean") %>%
  summarize(mean = mean(allRepl))


##########################
#Figure 2: Benefit concentration indicator across countries.
##########################

df %>%
  group_by(cntry) %>%
  filter(time=="Mean") %>%
  summarize(mean = mean(allRepl)) %>%
  arrange(+mean) %>%                               
  mutate(group = factor(cntry, cntry)) %>%   
  ggplot(aes(x=group, y=mean)) +                 
  geom_bar(stat="identity",fill="#333333")+
  annotate("segment", x = 1.5, xend = 1.5, y = .7, yend = .82,arrow=arrow())+
  annotate("segment", x = 1.5, xend = 1.5, y = .6, yend = .48,arrow=arrow())+
  annotate("text", x = c(2.5,2.5), y = c(.75,.55), 
           label = c("flat-rate", "earnings-related"),hjust=0, size=5) +
  xlab("Country") + ylab("Benefit concentration") +  coord_cartesian(ylim=c(0,.85))+
  scale_y_continuous(expand = c(0, 0)) + 
  theme_bw()+
  theme(panel.border=element_blank(),axis.line=element_line(),
        legend.position="bottom",legend.text = element_text(size = 14),
        legend.title = element_text(size=14),axis.text=element_text(size=12),
        axis.title=element_text(size=14)
  )

##########################

##########################
#Save figure
##########################

ggsave(file="figure_2.pdf", height = 5.83, width = 8.27, units = "in")

